package com.event.core.parse;

import cn.hutool.core.util.StrUtil;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/*
 * @description CacheableParse工厂
 * @author Bing
 * @date 2024/10/8 14:07
 **/
public class CacheableParseFactory {
    /**
     * 收集所有的CacheableParse
     */
    private Map<String, CacheableParse> cacheableParseMap = new ConcurrentHashMap<>();

    public CacheableParseFactory(Map<String, CacheableParse> map){
        cacheableParseMap.putAll(map);
    }

    /**
     * 根据key获取对应的CacheableParse
     * @param key
     * @return
     */
    public CacheableParse get(String key){
        if(StrUtil.isBlank(key)){
            key = "defaultCacheableParse";
        }
        return cacheableParseMap.get(key);
    }

    /**
     * 添加CacheableParse
     * @param key
     * @param cacheableParse
     */
    public void add(String key,CacheableParse cacheableParse){
        cacheableParseMap.put(key,cacheableParse);
    }
}
